package org.ee.config;

import io.undertow.UndertowOptions;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * undertow容器配置
 */
@Configuration
public class UndertowConfig {

    @Bean
    public UndertowServletWebServerFactory undertowServletWebServerFactory() {
        UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();

        factory.addBuilderCustomizers(builder -> builder.setServerOption(
                UndertowOptions.ENABLE_HTTP2, true
        ));
        // 添加更多自定义配置
        factory.addBuilderCustomizers(builder -> {
            builder.setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, 60000); // 请求超时 60s
            builder.setServerOption(UndertowOptions.MAX_CONCURRENT_REQUESTS_PER_CONNECTION, 500); // 每连接最大请求数
            builder.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true); // 强制保持连接
        });

        return factory;
    }
}
